﻿package mortal.game.view.common.tooltip.tooltips
{
    import com.mui.controls.*;
    import extend.language.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.mount.data.*;

    public class TooltipBless extends ToolTipScaleBg
    {
        private var _currentData:BlessData;
        private var _leftTime:SecTimerView;
        private var _timeTxt:GTextFiled;
        private var _desc:GTextFiled;
        private var _txt:GTextFiled;
        private var _currentBless:GTextFiled;

        public function TooltipBless()
        {
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_1:GTextFormat = null;
            setBg(ImagesConst.ToolTipBg);
            _loc_1 = GlobalStyle.textFormatChen;
            _loc_1.size = 13;
            _loc_1.bold = true;
            UIFactory.gTextField(Language.getString(20762), 0, 0, 100, 22, this, _loc_1);
            this._txt = UIFactory.gTextField("", 0, 30, 150, 22, this, GlobalStyle.textFormatlan);
            this._desc = UIFactory.gTextField("", 0, 60, 255, 180, contentContainer2D, GlobalStyle.textFormatBai, true);
            this._desc.autoSize = TextFieldAutoSize.LEFT;
            _loc_1 = GlobalStyle.textFormatHuang;
            this._currentBless = UIFactory.gTextField("0", 85, 2, 100, 22, contentContainer2D, _loc_1, true);
            this._timeTxt = UIFactory.gTextField(Language.getString(20763), 150, 31, 100, 22, contentContainer2D, _loc_1, true);
            _loc_1 = GlobalStyle.textFormatHong;
            this._leftTime = new SecTimerView();
            this._leftTime.width = 35;
            this._leftTime.autoSize = TextFieldAutoSize.LEFT;
            this._leftTime.mouseEnabled = false;
            this._leftTime.defaultTextFormat = _loc_1;
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.setParse(Language.getString(30055));
            this._leftTime.configEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            this._leftTime.x = 150;
            this._leftTime.y = 30;
            contentContainer2D.addChild(this._leftTime);
            return;
        }// end function

        override public function set data(param1) : void
        {
            this._currentData = param1 as BlessData;
            var _loc_2:* = Language.getStringByParam(20764, this._currentData.type, this._currentData.type, this._currentData.type, this._currentData.type);
            this._desc.htmlText = _loc_2;
            this._txt.text = Language.getStringByParam(20765, this._currentData.type);
            this._currentBless.text = this._currentData.bless.toString();
            super.data = param1;
            this.updateView();
            return;
        }// end function

        private function updateView() : void
        {
            if (this._leftTime.parent)
            {
                this._leftTime.parent.removeChild(this._leftTime);
            }
            if (this._currentData.blessClear)
            {
                if (this._currentData.bless > 0 && this._currentData.leftSeconds > 0)
                {
                    this._timeTxt.text = "";
                    this.updateTime();
                    this.addChild(this._leftTime);
                }
                else
                {
                    this._timeTxt.text = Language.getString(20763);
                    this._leftTime.setLeftTime(0);
                    this._leftTime.visible = false;
                }
            }
            else
            {
                this._timeTxt.text = Language.getString(20766);
                this._leftTime.stop();
                this._leftTime.visible = false;
            }
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (_loc_2 <= 0)
            {
                this._leftTime.stop();
                this._currentBless.text = "0";
                this._timeTxt.text = Language.getString(20763);
                if (this._leftTime.parent)
                {
                    this._leftTime.parent.removeChild(this._leftTime);
                }
            }
            else
            {
                this.addChild(this._leftTime);
            }
            return;
        }// end function

        private function updateTime() : void
        {
            var _loc_1:* = this._currentData.leftSeconds;
            if (_loc_1 > 3600)
            {
                this._leftTime.setParse(Language.getString(30055));
            }
            else if (_loc_1 < 3600)
            {
                this._leftTime.setParse(Language.getString(30056));
            }
            this._leftTime.setLeftTime(_loc_1);
            this._leftTime.visible = true;
            return;
        }// end function

    }
}
